<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author CHATERAB
 */

Class User extends CI_Model
{
 function login($username, $password)
 {
   $this -> db -> select('id, username, password,first_name,second_name');
   $this -> db -> from('user');
   $this -> db -> where('username', $username);
   $this -> db -> where('password',$password);
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
 
    function add($fistname, $secandname, $login, $mail, $password, $role) {
        $sql = "INSERT INTO user ( first_name,second_name,username,mail,password,role)  
        VALUES (" . $this->db->escape($fistname) . ","
                . " " . $this->db->escape($secandname) . ", "
                . "" . $this->db->escape($login)
                . ", " . $this->db->escape($mail)
                . ", " . $this->db->escape($password)
                . ", " . $this->db->escape($role) . ")";

        $this->db->query($sql);

        echo $this->db->affected_rows();
    }
    
    function selectAll(){
        $query = $this->db->query('SELECT id,first_name,second_name,username,mail,role, created_at from user ');
        return $query->result_array();
    }
   function delete($id){
        $query=$this->db->query("DELETE FROM `atlanticdigi_db`.`user` WHERE `user`.`id` = ".$id);
       
    }
    function  getToUpdate($id){
        $query=$this->db->query("SELECT * FROM  `user` WHERE  `user`.`id` =".$id );
        return $query->result_array();
    }
    function updateUser($id){
        
    }
}

